from fastapi import APIRouter, Depends, Query, Path, Body
from sqlalchemy.ext.asyncio import AsyncSession
from typing import List, Optional, Dict, Any
from module_admin.entity.vo.employee_social_security_vo import EmployeeSocialSecurityQueryModel, DeleteEmployeeSocialSecurityModel
from module_admin.service.employee_social_security_service import EmployeeSocialSecurityService
from utils.response_util import ResponseUtil
from config.get_db import get_db

# 构建路由
employeeSocialSecurityController = APIRouter(prefix='/system/employee_social_security')


@employeeSocialSecurityController.get('/list', summary='获取员工社保列表')
async def get_system_employee_social_security_list(
    page_num: int = Query(1, description='页码'),
    page_size: int = Query(10, description='每页数量'),
    employee_id: Optional[int] = Query(None, description='员工ID'),
    start_date: Optional[str] = Query(None, description='开始日期'),
    end_date: Optional[str] = Query(None, description='结束日期'),
    db: AsyncSession = Depends(get_db)
):
    """
    获取员工社保列表
    """
    security_query = EmployeeSocialSecurityQueryModel(
        page_num=page_num,
        page_size=page_size,
        employee_id=employee_id,
        start_date=start_date,
        end_date=end_date,
    )
    result = await EmployeeSocialSecurityService.get_employee_social_security_list_services(db, security_query)
    return ResponseUtil.success(data={"rows": result.rows, "total": result.total})


@employeeSocialSecurityController.get('/{security_id}', summary='获取员工社保详情')
async def get_system_employee_social_security(
    security_id: int = Path(..., description='社保ID'),
    db: AsyncSession = Depends(get_db)
):
    """
    获取员工社保详情
    """
    result = await EmployeeSocialSecurityService.get_employee_social_security_services(db, security_id)
    return ResponseUtil.success(data=result)


@employeeSocialSecurityController.post('', summary='新增员工社保')
async def add_system_employee_social_security(
    security: EmployeeSocialSecurityQueryModel = Body(..., description='社保信息'),
    db: AsyncSession = Depends(get_db)
):
    """
    新增员工社保
    """
    result = await EmployeeSocialSecurityService.add_employee_social_security_services(db, security)
    return ResponseUtil.success(data=result)


@employeeSocialSecurityController.put('/{security_id}', summary='修改员工社保')
async def update_system_employee_social_security(
    security_id: int = Path(..., description='社保ID'),
    security: EmployeeSocialSecurityQueryModel = Body(..., description='社保信息'),
    db: AsyncSession = Depends(get_db)
):
    """
    修改员工社保
    """
    result = await EmployeeSocialSecurityService.update_employee_social_security_services(db, security_id, security)
    return ResponseUtil.success(data=result)


@employeeSocialSecurityController.delete('/{security_id}', summary='删除员工社保')
async def delete_system_employee_social_security(
    security_id: int = Path(..., description='社保ID'),
    db: AsyncSession = Depends(get_db)
):
    """
    删除员工社保
    """
    result = await EmployeeSocialSecurityService.delete_employee_social_security_services(db, security_id)
    return ResponseUtil.success(data=result)


@employeeSocialSecurityController.get('/export', summary='导出员工社保')
async def export_system_employee_social_security(
    employee_id: Optional[int] = Query(None, description='员工ID'),
    start_date: Optional[str] = Query(None, description='开始日期'),
    end_date: Optional[str] = Query(None, description='结束日期'),
    db: AsyncSession = Depends(get_db)
):
    """
    导出员工社保
    """
    security_query = EmployeeSocialSecurityQueryModel(
        employee_id=employee_id,
        start_date=start_date,
        end_date=end_date,
    )
    result = await EmployeeSocialSecurityService.export_employee_social_security_services(db, security_query)
    return ResponseUtil.success(data=result)
